﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PalFramework;
using PalFramework.Template;

namespace PalBattleEmulator.Template
{
    public class ArrayTmpl : PalObjectTmpl, IArrayTmpl
    {
        private int count;

        public int Count
        {
            get { return count; }
            set { count = value; }
        }

        private List<ArrayCoordinate> coordinates;

        public List<ArrayCoordinate> Coordinates
        {
            get { return coordinates; }
            set { coordinates = value; }
        }


        public override void LoadData(Dictionary<string, string> data)
        {
            foreach (string key in data.Keys)
            {
                if (dictionary.ContainsKey(key))
                {
                    int type = dictionary[key];
                    string value = data[key];
                    switch (type)
                    {
                        case ID:
                            Id = Convert.ToInt32(value);
                            break;
                        case NAME:
                            Name = value;
                            break;
                        case COUNT:
                            Count = Convert.ToInt32(value);
                            break;
                        case COORDINATES:
                            string[] coorStrs = value.Split('|');
                            List<ArrayCoordinate> coors = new List<ArrayCoordinate>();
                            foreach (string coor in coorStrs)
                            {
                                coors.Add(new ArrayCoordinate(coor));
                            }
                            Coordinates = coors;
                            break;
                    }
                }

            }
        }

        public const int ID = 0;
        public const int NAME = 1;
        public const int COUNT = 2;
        public const int COORDINATES = 3;

        private static Dictionary<string, int> dictionary;

        static ArrayTmpl()
        {
            dictionary = new Dictionary<string, int>();
            dictionary.Add("id", ID);
            dictionary.Add("name", NAME);
            dictionary.Add("count", COUNT);
            dictionary.Add("coordinates", COORDINATES);
        }

    }

    
}
